# Maintainer: kpcyrd <kpcyrd[at]archlinux[dot]org>

pkgname=apko
pkgver=0.11.3
pkgrel=1
pkgdesc="Declarative APK-based container building tool with support for sigstore signatures"
url="https://github.com/chainguard-dev/apko"
arch=('loong64' 'x86_64')
license=('Apache-2.0')
depends=('apk-tools' 'alpine-keyring')
makedepends=('go')
source=("https://github.com/chainguard-dev/apko/archive/v${pkgver}/apko-${pkgver}.tar.gz")
sha256sums=('95c644591f54eecfab0ecc136cd53431da0835b22835f15096e242ef2d5b7c73')
b2sums=('1e5590ce6f95c045cf16ff5b91bf2b8300cb0cef85e40c13929e130617f13a74fff24c3953377a4310f11616f9932cdf58727ae037e640a2d7d90d9ec49f228e')

build() {
  cd "${pkgname}-${pkgver}"
  mkdir build
  CGO_LDFLAGS="${LDFLAGS}" \
    GOFLAGS="-trimpath -buildmode=pie -mod=readonly" \
    go build -o build/ -tags -tags=pivkey,pkcs11key ./...

  for i in bash fish zsh; do
    build/apko completion ${i} > ./apko.${i}
  done
}

check() {
  cd "${pkgname}-${pkgver}"
  # skip TestPublish: https://github.com/chainguard-dev/apko/issues/881
  go test ./... -skip TestPublish
}

package() {
  cd "${pkgname}-${pkgver}"
  install -Dm755 build/apko "${pkgdir}"/usr/bin/apko
  install -Dm644 apko.bash "${pkgdir}"/usr/share/bash-completion/completions/apko
  install -Dm644 apko.fish "${pkgdir}"/usr/share/fish/completions/apko.fish
  install -Dm644 apko.zsh "${pkgdir}"/usr/share/zsh/site-functions/_apko
}

# vim: ts=2 sw=2 et:
